﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QLNS.aspFrm
{
    public partial class frmQuanHeGiaDinh : System.Web.UI.Page
    {
        public string IDCB { get { return Request.QueryString["id"].ToString(); } }
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Data.DataTable dtTK = MakeTable();
            //doan nay co the bo 
            List<QLNS.QHGD> lstTK = QLNS.Models.QHGiaDinhModels.GetDSQHGDTheoCanBo(Convert.ToInt32(Request["id"].ToString()));
            foreach (var r in lstTK)
            {
                System.Data.DataRow row;
                row = dtTK.NewRow();
                this.FillDataRow(row, r);
                dtTK.Rows.Add(row);
            }

            //Tao 5 level cho phong ban


            CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            string strRptPath = Server.MapPath("~/") + "Reports//Report_QuanHeGiaDinh.rpt";
            //Loading Report
            rd.Load(strRptPath);

            // Setting report data source
            if (dtTK != null && dtTK.GetType().ToString() != "System.String")
                rd.SetDataSource(dtTK);


            CrystalReportViewer1.ReportSource = rd;
        }
        private void FillDataRow(System.Data.DataRow row, QLNS.QHGD r)
        {
            //System.Data.DataRow row = new System.Data.DataRow();

            row["QuanHe"] = r.QuanHe;
            row["HoVaTen"] = r.HoVaTen;
            row["NamSinh"] = r.NamSinh;
            row["QueQuan"] = r.QueQuan;
            row["NgheNghiep"] = r.NgheNghiep;
            row["ChucVu"] = r.ChucVu;
            row["DonViCongTac"] = r.DonViCongTac;
            row["DiaChi"] = r.DiaChi;
            row["GhiChu"] = r.GhiChu;


            //return row;
        }
        private System.Data.DataTable MakeTable()
        {
            // Create a new DataTable.
            System.Data.DataTable table = new System.Data.DataTable("Table");

            // Declare variables for DataColumn and DataRow objects.
            System.Data.DataColumn column;

            // Create new DataColumn, set DataType, 


            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "QuanHe";
            column.Caption = "Quan hệ";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "HoVaTen";
            column.Caption = "Họ và tên";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NamSinh";
            column.Caption = "Năm sinh";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "QueQuan";
            column.Caption = "Quê quán";
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgheNghiep";
            column.Caption = "Nghề nghiệp";
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ChucVu";
            column.Caption = "Chức vụ";
            table.Columns.Add(column);

           

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "DonViCongTac";
            column.Caption = "Đơn vị công tác";
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "DiaChi";
            column.Caption = "Địa chỉ";
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "GhiChu";
            column.Caption = "Ghi chú";
            table.Columns.Add(column);


            return table;
        }
    }
}